package com.chris.libs.base.x.mvpp.mvpp;

import android.content.Context;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.core.util.Consumer;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.LiveData;

/**
 * @author Chris chan
 * Create on: 2025/1/23 11:01
 * Use for:
 * Explain:
 */
public abstract class AbsViewProxy {
    protected Context context;
    protected View contentView;
    protected LifecycleOwner lifecycleOwner;

    public AbsViewProxy() {
    }

    public AbsViewProxy(@NonNull Context context, @NonNull View contentView, @NonNull LifecycleOwner lifecycleOwner) {
        this.context = context;
        this.contentView = contentView;
        this.lifecycleOwner = lifecycleOwner;
    }

    // 同一封装数据更新，简化代码
    protected <T> void update(LiveData<T> data, Consumer<T> consumer) {
        data.observe(this.lifecycleOwner, consumer::accept);
    }
}
